<?php

namespace app\item\controller;

use app\common\model\Configs;
use app\common\model\Domains;
use app\common\model\Quns;
use app\common\model\Shareinfos;
use dh2y\qrcode\QRcode;
use think\Request;

class Qun extends Base
{



    /* 整合自定义模板 */
    private function zhenghemuban($data='')
    {
        if ( !$data ) return $this->defaultTemplate();

        $data = json_decode($data, true);

        if ( !$data ) return $this->defaultTemplate();

        $str = '';
        foreach ($data as $k=>$v) {
            $str .= '<div class="ulgywoiksazn" next="1000">';
            $str .= '<div class="hd_img"><img src="'. $v['ico'] .'"></div>';
            $str .= '<div class="lrjfcxlgwi">';
            $str .= '<p class="name">'. urlencode($v['name']) .'</p>';

            if ( $v['type'] == 'img' ){

                $str .= '<div class="chat_box"><img src="'. $v['url'] .'"></div>';
            } else {

                $str .= '<div class="chat_box chat_txt">'. urlencode($v['url']) .'</div>';
            }

            $str .= '</div></div>';

        }
        return base64_encode($str);
    }

    /* 默认模板 */
    private function defaultTemplate()
    {
        return 'JTNDZGl2JTIwY2xhc3MlM0QlMjJ1bGd5d29pa3Nhem4lMjIlMjBuZXh0JTNEJTIyMTUwMCUyMiUzRSUwQSUyMCUyMCUyMCUyMCUzQ2RpdiUyMGNsYXNzJTNEJTIyaGRfaW1nJTIyJTNFJTNDaW1nJTIwc3JjJTNEJTIyJTJGc3RhdGljJTJGaW1nJTJGdHgxLmpwZyUyMiUyMGFsdCUzRCUyMiUyMiUyMCUyRiUzRSUzQyUyRmRpdiUzRSUwQSUyMCUyMCUyMCUyMCUzQ2RpdiUyMGNsYXNzJTNEJTIybHJqZmN4bGd3aSUyMiUzRSUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUzQ3AlMjBjbGFzcyUzRCUyMm5hbWUlMjIlM0UlRTUlQjAlOEYlRTQlQjklOUQlRDIlODklRDIlODklRDIlODklRDIlODklRTQlQjklOUQlM0MlMkZwJTNFJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTNDZGl2JTIwY2xhc3MlM0QlMjJjaGF0X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数';

        $url = fission('https') . '://' . Domains::getOneData(2) . url('item/qun/show', ['alias'=>$alias, getRandStr(8,15)=>getRandStr(8,15)]);
        $this->assign('url', $url);
        return view();
    }


    /* 页面展示 */
    public function show($alias='')
    {
        if ( !$alias ) return '无参数';

        if ( !isset($_SERVER['HTTP_REFERER']) ){
            $url = url('item/qun/index', ['alias'=>$alias]);
            $this->redirect($url);
        }

        /* 获取数据 */
        $data = Quns::where(['alias'=>$alias])->find();
        if ( !$data ) return '没有找到数据';

        /* 访问量 +1 */
        $data->setInc('view');

        /* 加载淘口令 */
        $data['taokouling'] = fission('taokouling');

        //随机群人数
	    //提取cookie里到群人数，或者随机获取，并保存到cookie
	    if ( cookie('?number') ){
		    $data['number'] = cookie('number');
	    } else {
		    $data['number'] = mt_rand(200, 400);
		    cookie('number', $data['number']+1, 10);
	    }


	    // 获取用户分享参数
	    // 如果没有数据，先添加默认数据
	    $shareinfo = Shareinfos::where('uid', $data['uid'])->find();
	    if ( count($shareinfo) < 1 ) {
		    $shareinfo = [
			    'uid'			=> $data['uid'],
			    // 聊天间隔时间
			    'wechat_time'	=> fission('wechat_time'),
			    // 分享背景图（先展示）（推荐群、好友）
			    'share_bg'		=> fission('share_bg'),
			    // 分享背景图（后更改）（推荐朋友圈）
			    'share_bg2'		=> fission('share_bg2'),
			    // 分享多少次后更换背景图
			    'huan_bg_num'		=> fission('huan_bg_num'),
			    // 先分享到群？先圈？
			    'share_xian_who'		=> fission('share_xian_who'),
			    // 分享到群次数
			    'share_qun_num'		=> fission('share_qun_num'),
			    // 分享到朋友圈次数
			    'share_quan_num'		=> fission('share_quan_num'),

			    // 分享触发提示
			    'share_alert_0'	=> fission('share_alert_0'),
			    // 分享提示1
			    'share_alert_1'	=> fission('share_alert_1'),
			    // 分享提示2
			    'share_alert_2'	=> fission('share_alert_2'),
			    // 分享提示3
			    'share_alert_3'	=> fission('share_alert_3'),
			    // 分享提示4
			    'share_alert_4'	=> fission('share_alert_4'),
			    // 分享提示5
			    'share_alert_5'	=> fission('share_alert_5'),
			    // 分享提示6
			    'share_alert_6'	=> fission('share_alert_6'),
			    //分享完成二维码提示
			    'share_end_msg'	=> fission('share_end_msg'),
		    ];
		    Shareinfos::create($shareinfo);
	    }

        /* 下一步链接 */
        if ( $data['ltck'] == 2 ){
	        $data['next_url'] = fission('https') . '://' . Domains::getOneData(3) . url('item/qun/share', ['alias'=>$alias, getRandStr(8,15)=>getRandStr(8,15)]);
        } else {
	        $data['next_url'] = url('item/qun/wechat', ['alias'=>$alias, getRandStr(8,15)=>getRandStr(8,15)]);
        }

        //加载到模板
        $this->assign(['data'=>$data, 'jsondata'=>base64_encode(json_encode($data))]);

        return view();
    }


    /* 展示仿聊天窗口 */
    public function wechat($alias='')
    {
        if ( !$alias ) return '无参数';

        if ( !isset($_SERVER['HTTP_REFERER']) ){
            $url = url('item/qun/index', ['alias'=>$alias]);
            $this->redirect($url);
        }

        /* 获取数据 */
        $data = Quns::where(['alias'=>$alias])->find();
        if ( !$data ) return '没有找到数据';

        /* 加载淘口令 */
        $data['taokouling'] = fission('taokouling');

        //随机群人数
	    //提取cookie里到群人数，或者随机获取，并保存到cookie
	    if ( cookie('?number') ){
		    $data['number'] = cookie('number');
	    } else {
		    $data['number'] = mt_rand(200, 400);
		    cookie('number', $data['number']+1, 10);
	    }


	    /* 把字符串转换成数组 */
        $qrcode = explode('||', $data['qrcode']);
        //从多张二维码里，随机获取一张
        $data['qrcode'] = $qrcode[mt_rand(0, count($qrcode)-1)];

	    /* 下一步链接 获取分享链接 */
	    $data['next_url'] = fission('https') . '://' . Domains::getOneData(3) . url('item/qun/share', ['alias'=>$alias, getRandStr(8,15)=>getRandStr(8,15)]);

        /* 获取行业模板 */
        if ( $data['muban'] == 0 ){
            $data['hangye'] = $this->zhenghemuban($data['zidingyi']);
        } else {
            $data['hangye'] = $this->defaultTemplate();
        }



		// 获取用户分享参数
	    // 如果没有数据，先添加默认数据
	    $shareinfo = Shareinfos::where('uid', $data['uid'])->find();
	    if ( count($shareinfo) < 1 ) {
		    $shareinfo = [
			    'uid'			=> $data['uid'],
			    // 聊天间隔时间
			    'wechat_time'	=> fission('wechat_time'),
			    // 分享背景图（先展示）（推荐群、好友）
			    'share_bg'		=> fission('share_bg'),
			    // 分享背景图（后更改）（推荐朋友圈）
			    'share_bg2'		=> fission('share_bg2'),
			    // 分享多少次后更换背景图
			    'huan_bg_num'	=> fission('huan_bg_num'),
			    // 先分享到群？先圈？
			    'share_xian_who'	=> fission('share_xian_who'),
			    // 分享到群次数
			    'share_qun_num'		=> fission('share_qun_num'),
			    // 分享到朋友圈次数
			    'share_quan_num'	=> fission('share_quan_num'),

			    // 分享触发提示
			    'share_alert_0'	=> fission('share_alert_0'),
			    // 分享提示1
			    'share_alert_1'	=> fission('share_alert_1'),
			    // 分享提示2
			    'share_alert_2'	=> fission('share_alert_2'),
			    // 分享提示3
			    'share_alert_3'	=> fission('share_alert_3'),
			    // 分享提示4
			    'share_alert_4'	=> fission('share_alert_4'),
			    // 分享提示5
			    'share_alert_5'	=> fission('share_alert_5'),
			    // 分享提示6
			    'share_alert_6'	=> fission('share_alert_6'),
			    //分享完成二维码提示
			    'share_end_msg'	=> fission('share_end_msg'),
		    ];
		    Shareinfos::create($shareinfo);

		    /* 聊天间隔时间 */
		    $data['wechat_time'] = fission('wechat_time');

	    } else {

		    /* 聊天间隔时间 */
		    $data['wechat_time'] = $shareinfo['wechat_time'];

	    }

        /* 加载到模板 */
        $this->assign(['data'=>$data, 'jsondata'=>base64_encode(json_encode($data))]);
//        $this->assign(['conf'=>$shareinfo, 'jsonconf'=>base64_encode(json_encode($shareinfo))]);

	    return view();

    }



	/* 分享 */
	public function share($alias='')
	{
		if ( !$alias ) return '无参数';

		if ( !isset($_SERVER['HTTP_REFERER']) ){

			$url = url('item/qun/index', ['alias'=>$alias]);
			$this->redirect($url);
		}

		$data = Quns::where(['alias'=>$alias])->find();
		if ( !$data ){
			return '没有找到数据';
		}

		/* 加载淘口令 */
		$data['taokouling'] = fission('taokouling');

		if ( $data['share_img'][0] == '/' ) {

			if ( (! empty($_SERVER['REQUEST_SCHEME']) && $_SERVER['REQUEST_SCHEME'] == 'https') || (! empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') || (! empty($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] == '443') ) {
				$_SERVER['REQUEST_SCHEME'] = 'https';
			} else {
				$_SERVER['REQUEST_SCHEME'] = 'http';
			}

			$data['share_img'] = $_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['HTTP_HOST'] . $data['share_img'];
		}



		//把字符串转换成数组
//		$share_title = explode('||', $data['share_title']);
//		$share_desc  = explode('||', $data['share_desc']);
		$qrcode      = explode('||', $data['qrcode']);

		//获取随机数据
//		$data['share_title'] = $share_title[mt_rand(0, count($share_title)-1)];
//		$data['share_desc']  = $share_desc[mt_rand(0, count($share_desc)-1)];
		$data['qrcode']      = $qrcode[mt_rand(0, count($qrcode)-1)];

		$data['share_link']  = fission('https') . '://' . $_SERVER['HTTP_HOST'] . url('item/qun/index', ['alias'=>$alias]);

		/* 下一步链接 */
		if ( $data['share_end_type'] == 2 ){
			$data['share_end_url'] = fission('https') . '://' . Domains::getOneData(2) . url('item/qun/qrcode', ['alias'=>$alias, getRandStr(8,15)=>getRandStr(8,15)]);
		}

		//获取全部配置

		$shareinfo = Shareinfos::where('uid', $data['uid'])->find();

		$this->assign(['data'=>$data, 'jsondata'=>base64_encode(json_encode($data))]);
		$this->assign(['conf'=>$shareinfo, 'jsonconf'=>base64_encode(json_encode($shareinfo))]);

		return view();
	}


	/* 展示二维码 */
	public function qrcode($alias='')
	{
		if ( !$alias ) return '无参数';

		if ( !isset($_SERVER['HTTP_REFERER']) ){

			$url = url('item/qun/index', ['alias'=>$alias]);
			$this->redirect($url);
		}

		$data = Quns::where(['alias'=>$alias])->find();
		if ( !$data ){
			return '没有找到数据';
		}

		/* 加载淘口令 */
		$data['taokouling'] = fission('taokouling');

		$shareinfo = Shareinfos::where('uid', $data['uid'])->find();

		$qrcode      = explode('||', $data['qrcode']);
		$data['qrcode'] = $qrcode[mt_rand(0, count($qrcode)-1)];
		$data['share_end_msg']  = $shareinfo['share_end_msg'];

		//提取cookie里到群人数，或者随机获取，并保存到cookie
		if ( cookie('?number') ){
			$data['number'] = cookie('number');
		} else {
			$data['number'] = mt_rand($data['min_num'], $data['max_num']);
			cookie('number', $data['number']+1, 10);
		}

		//加载到模板
		$this->assign(['data'=>$data, 'jsondata'=>base64_encode(json_encode($data))]);

		return view();
	}


}

